let StuRevisitTable;
let ocTable;
let mainTipPotentialTable;
let trackRemindTable;
let stuOrderInfoTable;
let potentialStuTable;
let mainTipRelLeadsTable;
let newStudentTable;
let bookingLctClassTable;
let noReminderTimeTable;
let surplusClassLessNUmTable;
let oldStuFollowTable;
let autoFailBookedTable;
let classWeekInfoTable;
let classBookedTodayTable;
let lastTwoScoreInfoTable;
let ccId = $(".select_item").attr("value");
    //初始化页面框架
    $(function(){
        let configList = selectSort(ccConfig);
        for(let i = 0;i<configList.length;i++){
            if(configList[i].state != 0){
                console.log("configList[i].method=>",configList[i].method)
                 eval(configList[i].method);
            }
        }

        $(".selectbox").click(function(e){
            $(".selectBox").toggle();
            e.stopPropagation();
        });

        $("#selectboxImg").click(function(e){
            $(".selectBox").toggle();
            e.stopPropagation();
        });

        // 点击关闭按钮
        $(".close_icon").click(function(){
            $(this).parents('.main-box').remove()
        });
        //学员属性列表
        getStuStateList();
    });

    //点击排序设置，获取 排序列表
    function sortConfig(){
        var configList =  selectSort(ccConfig);
        //排序列表公共方法
        pubSortList(configList);
    }

    //还原默认设置 方法
    function restoreDefaultConfig(){
        //调用公共方法
       restoreDefault(ccConfig);
    }

    /*约课顾问下潜在学员  客户属性列表*/
    function getStuStateList(){
        $.ajax({
            type : 'post',
            url : '/YkNewMainCtl/revisitInfoList',
            data : {},
            // async:false,
            dataType : 'json',
            success : function(data) {
                let html = "";
                for(let i = 0 ;i<data.revisitInfoList.length;i++){
                    if (data.revisitInfoList[i].parent_id>0){
                        html+='<li style="line-height: 30px; padding-left: 15px;" onclick="selectStuRevisit('+data.revisitInfoList[i].id+',\''+data.revisitInfoList[i].name+'\','+data.revisitInfoList[i].parent_id+')"  value='+data.revisitInfoList[i].id+'>'+data.revisitInfoList[i].name+'</li>';
                    } else {
                        html+='<li style="line-height: 30px;" onclick="selectStuRevisit('+data.revisitInfoList[i].id+',\''+data.revisitInfoList[i].name+'\','+data.revisitInfoList[i].parent_id+')"  value='+data.revisitInfoList[i].id+'>'+data.revisitInfoList[i].name+'</li>';
                    }
                }
                $("#stuRevisit").html(html);
            }
        });
    }

    //点击重新加载 待约学员
    function selectStuRevisit(id,name,parentId){
        let revisitId= $("#appointedStudent").html(name).attr("value");
        $("#appointedStudent").attr("data-parentid",parentId);
        let isReload=true;
        if ((revisitId!=='6' && (id===6 || parentId===6)) || (revisitId==='6' && id!==6 && parentId!==6)) {
            isReload=false;
        }
        if (isReload) {
            mainTipPotentialTable.reload("mainTipPotential", {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    "state" : id
                }
            });
        }else {
            mainTipPotentialTableRender(id,name);
        }
    }
    //创建待约学员表格
    function mainTipPotentialTableRender(id,name) {
        if (id===null || id===""){
            id=6;
        }
        $("#appointedStudent").html(name).attr("value",id);
        let initTableCols=[
            {field:'stuLoginName', title: '学号',fixed: 'left',
                templet : function (row) {
                    return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',14)">'+row.stuLoginName+'</a>';
                }
            },
            {field:'cnName', title: '姓名',fixed: 'left'},
            {field:'channelName', title: '客户渠道',fixed: 'left'},
            {field:'phone', title: '手机'}
        ];
        let parentId=$("#appointedStudent").attr("data-parentid");
        if (id===6 || parentId==="6") {
            initTableCols=[
                {field:'stuLoginName', title: '学号',fixed: 'left',
                    templet : function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',14)">'+row.stuLoginName+'</a>';
                    }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'channelName', title: '客户渠道',fixed: 'left'},
                {field:'phone', title: '手机',fixed: 'left'},
                {field:'releaseTime', title: '最近完成的DEMO课',
                    templet : function (row) {
                        //console.log(row.releaseTime);
                        if (row.releaseTime!==null && row.releaseTime!==undefined){
                            return formatDateMin(row.releaseTime,1);
                        }
                        return "";
                    }
                }
            ];
        }
        mainTipPotentialTable.render({
            elem: '#5',
            url:'/CCNewMain/appointedStudentByccId',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId,"state" : id},
            id : "mainTipPotential",
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                groups: 5, //只显示 1 个连续页码
                first: false, //不显示首页
                last: false, //不显示尾页
                theme: '#00A0E9'
            },
            cols: [
                initTableCols
            ]
        });
    }
    //提醒列表 1
    function trackRemindByccId(id,tableName){
        let html = '<span class="date_box">';
         html +='   <a href="javascript:" style="color: #fff" id="trackRemindDate">2019-01-07</a>';
         html +='<i class="fa fa-calendar" style="margin-left: 5px"></i>';
         html +='</span>';
         pubHtml(id,1,tableName,html,"");
    }

    //订单到期列表 2
    function stuOrderInfoByCC(id,tableName){
         pubHtml(id,2,tableName,"","");
    }

    //已约未上 3
    function demoMissedListByCC(id,tableName){
         let html = '<span class="date_box" >';
         html +='   <a href="javascript:" style="color: #fff" id="demoMissed">2019-01-07</a>';
         html +='<i class="fa fa-calendar" style="margin-left: 5px;"></i>';
         html +='</span>';
         pubHtml(id,3,tableName,html,"");

    }
    //潜在客户 4
    function mainTipPotentialByCCId(id,tableName){
        pubHtml(id,2,tableName,"","");
    }

    //待约客户 5
    function appointedStudent(id,tableName){
         let html = '<div class="selectBox" style="border: 1px solid #bdb4b4;">' ;
            html +='   <ul class="list-unstyled" id="stuRevisit">' ;
            html +='   </ul>' ;
            html +='</div>' ;
        let html2 = '<span class="selectbox" id="appointedStudent" style="cursor: pointer;">已上可跟进</span>';
            html2+='<img src="../../static/img/select_icon.png" id="selectboxImg"/>';
        pubHtml(id,3,tableName,html2,html);
    }
    //Ref Leads 6
    function mainTipRelLeadsByCC(id,tableName){
        pubHtml(id,2,tableName,"","");
    }
    //新学员 7
    function mainTipNewStudentByCCId(id,tableName){
        pubHtml(id,3,tableName,"","");
    }
    //oc调查问卷 8
    function ocInfoByCC(id,tableName){
        pubHtml(id,2,tableName,"","");
    }

    //老师投诉学员 9
    function teacherRank(id, tableName) {
        let html = '<div class="form-inline" style="float: left;margin-right: 10px;">' ;
        html +='<input id="teacherRankSearchKey" type="search" class="form-control" style="border-top-right-radius:0;border-bottom-right-radius:0;" placeholder="查询关键字">' ;
        html +='<button type="button" class="btn btn-primary" onclick="teacherRankReload()" style="border-top-left-radius:0;border-bottom-left-radius:0;">搜索</button>' ;
        html +='</div>' ;
        pubHtml(id, 3, tableName, html, "");
    }

    //近月旷课3次以上学员 10
    function abnormalunFinishLessons(id, tableName) {
        pubHtml(id, 1, tableName, "", "");
    }

    //学管师学员上完中教课提醒家长会课程 11
    function bookingLctClass(id, tableName) {
        let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
        html += '<select id="yearMonth" class="form-control" style="margin-right: 5px;" onchange="reloadBookingLctClass()"><option value="0">本月</option><option value="-1">上月</option></select>';
        html += '<select id="finishId" class="form-control" onchange="reloadBookingLctClass()"><option value="0">未完成</option><option value="1">已完成</option></select>';
        html += '</div>';
        pubHtml(id, 1, tableName, html, "");
    }

    //未设置提醒动态的学员列表
    function noReminderTime(id, tableName){
        pubHtml(id, 2, tableName, "", "");
    }

    //13 订单总课时少于40节
    function surplusClassLessNUm(id, tableName){
        pubHtml(id, 2, tableName, "", "");
    }

    //老学员跟进 14
    function oldStuFollow(id, tableName) {
        let html = '<div style="float: left;margin-top: 10px;margin-right: 10px;">';
        html += '<select id="followDays" class="form-control" onchange="oldStuFollowBySsc()">' +
            '<option value="">未回访天数</option>' +
            '<option value="10">10~19天</option>' +
            '<option value="20">20~29天</option>' +
            '<option value="30">>=30天</option>' +
            '</select>';
        html += '</div>';
        pubHtml(id, 3, tableName, html, "");
    }

    //自动约课失败记录
    function autoFailBooked(id, tableName){
        pubHtml(id, 2, tableName, "", "");
    }

    //上课态度三星以下
    function classAttitude(id, tableName){
        pubHtml(id, 3, tableName, "", "");
    }

    //周课数少于3节
    function classWeekInfo(id, tableName){
        let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
        html += '<select id="weekId" class="form-control" onchange="reloadClassWeekInfo()"><option value="">选择周记录</option><option value="-1">上周</option><option value="0">本周</option><option value="1">下周</option></select>';
        html += '</div>';
        pubHtml(id, 3, tableName, html, "");
    }

    //周课数少于3节
    function classBookedToday(id, tableName){
        let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
        html += '<select id="classState" class="form-control" onchange="reloadClassBookedToday()"><option value="0">课程状态</option><option value="1" selected="selected">待上课</option><option value="2">已完成</option><option value="3">已旷课</option><option value="4">已取消</option></select>';
        html += '</div>';
        pubHtml(id, 4, tableName, html, "");
    }

    //学员最近成绩变化
    function lastTwoScoreInfo(id, tableName) {
        pubHtml(id, 3, tableName, "", "");
    }

    //cc 提醒数据表渲染 1-1
    layui.use(['table','laydate'], function(){
          var table = layui.table;
          var laydate = layui.laydate;
          trackRemindTable = table;
          table.render({
            elem: '#1',
            url:'/CCNewMain/selectTrackRemindByccId',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                  {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',10,'+row.remindId+')">'+row.stuLoginName+'</a>';
                      }},
                  {field:'cnName', title: '姓名',fixed: 'left'},
                  {field: 'releaseTime', title: '提醒时间',
                         templet :function (row){
                            if (row.expired==1){
                                return '<span style="color: #bd2130;">'+FormatTime(row.releaseTime)+'</span>';
                            }else {
                                return '<span style="color: #1abd76;">'+FormatTime(row.releaseTime)+'</span>';
                            }
                         }
                    },
                 {field:'remark', title: '客户属性'}
                ]
            ],
            id : "selectTrackRemind"
        });
        //日期插件  重新加载
        laydate.render({
          elem:"#trackRemindDate",//制定元素
          value: new Date(),
          done:function(value,date){//value, date, endDate点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
             //执行重载
            table.reload("selectTrackRemind", {
                page: {
                  curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    "searchDate" : value
                }
            });
          }
        });
    });

    //提醒列表 reload
    function trackRemindBycc(){
         trackRemindTable.reload("selectTrackRemind", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

    //cc 订单到期列表渲染 2-2
    layui.use('table', function(){
        var table = layui.table;
        stuOrderInfoTable  = table;
        table.render({
            elem: '#2',
            url:'/CCNewMain/searchStuOrderInfoByCC',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                  {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',11)">'+row.stuLoginName+'</a>';
                      }},
                  {field:'cnName', title: '姓名',fixed: 'left'},
                  {field:'packageName', title: '订单名称'},
                  {field: 'surplusValid', title: '到期日期',
                         templet :function (row){
                            return FormatTime(row.surplusValid,0);
                         }
                    },
                 {field:'remainingCourses', title: '剩余币/课时数'}
                ]
            ],
            id : "stuOrderInfo"
        });
    });

    //订单到期 reload
    function stuOrderInfo(){
        stuOrderInfoTable.reload("stuOrderInfo", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

    //cc 已约未上 3-3
    layui.use(['table','laydate'], function(){
          var table = layui.table;
          var laydate = layui.laydate;
          StuRevisitTable = table;
          table.render({
            elem: '#3',
            url:'/CCNewMain/demoMissedListByCC',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',12)">'+row.stuLoginName+'</a>';
                      }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'ccName', title: '课程顾问',fixed: 'left'},
                {field: 'surplusValid', title: '上课时间',
                     templet :function (row){
                        return formatDateMin(row.releaseTime,1);
                     }
                },
                {field:'teacherName', title: '上课老师',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="teacherInfo('+row.teacherId+')">'+row.teacherName+'</a>';
                      }
                },
            ]
            ],
            id : "demoMissedList"
        });
        //日期插件  重新加载
        laydate.render({
          elem:"#demoMissed",//制定元素
          value: new Date(),
            trigger: 'click',
          done:function(value,date){//value, date, endDate点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
             //执行重载
            table.reload("demoMissedList", {
                page: {
                  curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    "searchDate" : value
                }
            });
          }
        });
    });



    //已约未上 reload
    function demoMissedList(){
        StuRevisitTable.reload("demoMissedList", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

    //cc 潜在客户 4-4
    layui.use('table', function(){
          var table = layui.table;
          potentialStuTable = table;
          table.render({
            elem: '#4',
            url:'/CCNewMain/selectMainTipPotentialByCCId?state=1',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',13)">'+row.stuLoginName+'</a>';
                      }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'channelName', title: '客户渠道',fixed: 'left'},
                {field:'phone', title: '手机'}
            ]
            ],
            id : "potentialStu"
        });
    });

    //潜在客户 reload
    function potentialStu(){
        potentialStuTable.reload("potentialStu", {
            page: {
              curr: 1 //重新从第 1 页开始
            },
            where : {
                "state" : 1
            }
         });
    }

    //cc 待约学员 5-5
    layui.use('table', function(){
        let table = layui.table;
        mainTipPotentialTable = table;
        mainTipPotentialTableRender(6,"已上可跟进");
    });

    //待约学员 reload
    function appointedStu(){
        mainTipPotentialTable.reload("mainTipPotential", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

     //Ref leads 6-6
    layui.use('table', function(){
          var table = layui.table;
          mainTipRelLeadsTable = table;
          table.render({
            elem: '#6',
            url:'/CCNewMain/selectMainTipRelLeadsByCC',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',15)">'+row.stuLoginName+'</a>';
                      }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'channelName', title: '客户渠道',fixed: 'left'},
                {field:'phone', title: '手机'}
            ]
            ],
            id : "mainTipRelLeads"
        });
    });

    //Ref leads reload
    function mainTipRelLeads(){
         mainTipRelLeadsTable.reload("mainTipRelLeads", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

     //新学员 7-7
    layui.use('table', function(){
          var table = layui.table;
          newStudentTable = table;
          table.render({
            elem: '#7',
            url:'/CCNewMain/selectMainTipNewStudentByCCId',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',16)">'+row.stuLoginName+'</a>';
                      }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'remark', title: '购买天数',fixed: 'left'},
                {field:'phone', title: '手机'}
            ]
            ],
            id : "newStudent"
        });
    });

    //新学员  reload
    function newStudent (){
        newStudentTable.reload("newStudent", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

     //oc 问卷调查 8-8
    layui.use('table', function(){
          var table = layui.table;
          ocTable = table;
          table.render({
            elem: '#8',
            url:'/CCNewMain/selectOcInfoByCC',
            method: 'POST', //方式
            height: "400",
            loading: true, //翻页加loading
            where:{"ccId" :  ccId},
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              groups: 5, //只显示 1 个连续页码
              first: false, //不显示首页
              last: false, //不显示尾页
              theme: '#00A0E9'
            },
            cols: [
                [
                {field:'stuLoginName', title: '学号',fixed: 'left',
                      templet : function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',17)">'+row.stuLoginName+'</a>';
                      }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'phone', title: '手机'},
                {field:'phone', title: '手机',style:"",
                      templet : function (row) {
                        return '<a href="javascript:" class="icon" rel="popover" id="dialing'+row.id+'" onclick="call(\''+row.phone+'\','+row.id+')">' +
                            '    <img src="/static/img/icon/telephone_y.png" class="img-circle" alt="点击可拨打电话" title="点击可拨打电话">' +
                            '  </a>'
                    }
                },
                {field:'state', title: '未回访',
                      templet : function (row) {
                         return '<a url="/questionnaireOc/questionnairePaper?personId='+row.id+'&lessonId='+row.lessonId+'' +'&addUserName=&addUserId='+
                             '&enName='+row.enName+'&cnName='+row.cnName+'&teacher='+row.teacherName+'&releaseTime='+ FormatTime(row.releaseTime,1)+
                             '&sscName='+row.sscName+'&studentLogin='+row.stuLoginName+'" ' +
                             'class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="ocQuestion(this)" href="javascript:void(0);">未回访</a>';
                      }
                },
            ]
            ],
            id : "OcInfo"
        });
    });

//cc 老师投诉学员 列表渲染 8-8
layui.use('table', function () {
    var table = layui.table;
    teacherRankTable = table;
    table.render({
        elem: '#9',
        url: '/CCNewMain/selectTeacherRank',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',width : '15%',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',8)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left',width : '10%'},
                {field: 'classNum', title: '次数',width : '8%'},
                {field: 'teacherName', title: '老师',width : '10%'},
                {
                    field: 'releaseTime', title: '上课时间',width : '18%',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },
                {field:'complaint',title:'投诉内容',width : '32%'},
                {
                    field: '', title: '操作',width : '10%',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="teacherReply(' + row.lessonId + ',8)" href="javascript:void(0);"> Edit </a>';
                    }
                },
            ]
        ],
        id: "teacherRankId"
    });
});

    //oc 问卷 reload
    function ocQuestionReload (){
         ocTable.reload("OcInfo", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
         });
    }

    function ocQuestion(obj) {
       var url = $(obj).attr("url");
       layer.open({
                type: 2,
                title: false,
                closeBtn: 1, //显示关闭按钮
                shade: [0.5],
                area: ['60%', '95%'],
                //offset: 'rb', //右下角弹出
                // time: 2000, //2秒后自动关闭
                anim: 2,
                content: [url, 'yes'], //iframe的url，no代表不显示滚动条
                end: function () { //此处用于演示
                }
        });
    }

    //点击重新加载 待约学员
    function ocReload(){
         StuRevisitTable.reload("OcInfo", {
            page: {
              curr: 1 //重新从第 1 页开始
            }
        });
    }

    /**
     * 接听方式选择
     * @param phone
     * @param id
     * @returns
     */
    function call(phone,id){
        var html = '<div style="font-size: 15px">请选择接听方式</div>';
        html +='<div class="layui-form-item" style=" margin-top: 12px;margin-left: 10px;">' ;
        html += '<button class="layui-btn layui-btn-normal layui-btn-sm" id="saveViod" lay-submit="" lay-filter="demo1" onclick="callOut(\''+phone+'\',1)">手机接听</button>' ;
        html +='<button class="layui-btn layui-btn-warm layui-btn-sm" id="saveViod2" lay-submit="" lay-filter="demo1" onclick="callOut(\''+phone+'\',2)">企话宝接听</button>' ;
        html +='<button style="margin-top: 9%;margin-left: 28%;" type="reset" class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">稍后再拨</button>' ;
        html += '</div>' ;
        layer.tips(html, '#dialing'+id, {
            time : false,
            tips: [1, '#78BA32']
        });
    }

//老师投诉回复 弹窗
function teacherReply(lessonId) {
    //打开排序规则 列表弹窗
    var html = '<div class="layui-form-item layui-form-text">';
    html += '<div class="layui-input-block" style="margin-left: 16px;margin-top: 5px;">';
    html += '      <textarea placeholder="请输入内容" class="layui-textarea" id="reply" style="width: 330px;height: 130px;"></textarea>';
    html += '    </div>';
    html += '</div>';
    html += '<div class="layui-form-item">';
    html += '<div class="layui-input-block">';
    html += '<button class="layui-btn" lay-submit="" lay-filter="demo1" onclick="submitReply(' + lessonId + ')">提交</button>';
    html += '<button type="reset" class="layui-btn layui-btn-primary" onclick="layer.closeAll()">取消</button>';
    html += '</div>';
    html += '</div>';
    layer.open({
        title: "输入处理结果",
        type: 1,
        area: ['360px', '250px'],
        shadeClose: false, //点击遮罩关闭
        scrollbar: false, // 父页面 滚动条 禁止
        content: html
    });
}

//提交老师投诉回复
function submitReply(lessonId) {
    var reply = $("#reply").val().trim();
    if (reply == '') {
        layer.msg("回复内容不能为空");
        return;
    }
    $.ajax({
        type: "POST", //提交方式
        url: "/SSCNewMain/addTeacherRankReply",//路径
        data: {
            "lessonId": lessonId,
            "reply": reply
        },//数据，这里使用的是Json格式进行传输JSON.stringify(data),
        dataType: "json",
        success: function (data) {
            if (data.code > 0) {
                layer.msg("回复提交成功", {
                    offset: ['50%'],
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    teacherRankReload();
                    layer.closeAll();
                });
            } else {
                layer.msg("提交失败");
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}

//投诉列表查询重载
function teacherRankReload(){
    teacherRankTable.reload("teacherRankId", {
        page: {
            curr: 1 //重新从第 1 页开始
        }, where: {
            "searchKey": $("#teacherRankSearchKey").val()
        }
    });
}

//ssc 近月旷课5次以上学员 列表渲染 10
layui.use('table', function () {
    var table = layui.table;
    abnormalunFinishTable = table;
    table.render({
        elem: '#10',
        url: '/CCNewMain/abnormalunFinishLessons',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',\'c1\')">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'phone', title: '手机'},
                {field: 'totalNoShow', title: '近30天次数'},
                {field: 'remark', title: '新增次数'},
                {
                    field: '', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="publishStuDynamic(' + row.id + ',\'c1\')" href="javascript:void(0);"> 完 成 </a>';
                    }
                },
            ]
        ],
        id: "abnormalunFinishLessons"
    });
});

//近月旷课3次以上学员面板  点击完成并发布动态后，重新加载该面板
function reloadAbnormalunFinishLessons() {
    abnormalunFinishTable.reload("abnormalunFinishLessons", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//cc 学管师学员上完中教课提醒家长会课程 列表渲染 11
layui.use('table', function () {
    let table = layui.table;
    bookingLctClassTable = table;
    table.render({
        elem: '#11',
        url: '/CCNewMain/booking/lct/class',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId,"finishId": $("#finishId").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                         return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\')">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left',
                    templet: function (row) {
                        let td= row.cnName;
                        if (row.newUser===1){
                            td+='&nbsp;&nbsp;<img alt="" src="../../static/img/new.gif">';
                        }
                        return td;
                    }
                },
                {field: 'releaseTime', title: '中教课完成时间',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },
                {field: 'submitTime', title: '报告生成时间',
                    templet: function (row) {
                        return '<span>' + FormatTime(row.submitTime) + '</span>';
                    }
                },
                {field: 'addTime', title: '最后一次家长会',
                    templet: function (row) {
                        if (row.addTime!=null){
                            return '<span>' + FormatTime(row.addTime) + '</span>';
                        }else {
                            return '';
                        }
                    }
                },
            ]
        ],
        id: "bookingLctClass"
    });
});

function reloadBookingLctClass() {
    bookingLctClassTable.reload("bookingLctClass", {
        page: {
            curr: 1 //重新从第 1 页开始
        }, where: {
            "finishId": $("#finishId").val(),
            "yearMonth": $("#yearMonth").val()
        }
    });
}

// 12 未设置动态提醒的学员名单
layui.use('table', function () {
    let table = layui.table;
    noReminderTimeTable = table;
    table.render({
        elem: '#12',
        url: '/CCNewMain/no/reminder/time/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\')">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'revisitName', title: '客户属性'},
                {field: 'channelName', title: '注册渠道'},
            ]
        ],
        id: "noReminderTime"
    });
});

//13 订单总课时少于40节
layui.use('table', function () {
    let table = layui.table;
    noReminderTimeTable = table;
    table.render({
        elem: '#13',
        url: '/CCNewMain/order/surplus/class/num/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\')">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'surplusClass', title: '剩余课时/币'},
            ]
        ],
        id: "surplusClassLessNUm"
    });
});

//cc 老学员跟进 列表渲染 5-5
layui.use('table', function () {
    var table = layui.table;
    oldStuFollowTable = table;
    table.render({
        elem: '#14',
        url: '/CCNewMain/oldStuFollow',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId,"followDays": $("#followDays").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',7)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'phone', title: '手机'},
                {field: 'testMark', title: '未回访天数'}
            ]
        ],
        id: "oldStuFollow"
    });
});
//老学员跟进 reload
function oldStuFollowBySsc() {
    oldStuFollowTable.reload("oldStuFollow", {
        page: {
            curr: 1 //重新从第 1 页开始
        },where: {
            "followDays": $("#followDays").val()
        }
    });
}
//自动约课失败记录
layui.use('table', function () {
    var table = layui.table;
    autoFailBookedTable = table;
    table.render({
        elem: '#15',
        url: '/CCNewMain/auto/booked/fail/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',width :'20%',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',28)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left',width :'15%'},
                {field: 'releaseTime', title: '预约课程时间',width :'20%',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },
                {field: 'remark', title: '失败原因',width :'25%'},
                {field: 'addTime', title: '操作时间',width :'20%',
                    templet: function (row) {
                        return '<span>' + FormatTime(row.addTime) + '</span>';
                    }
                },
            ]
        ],
        id: "autoFailBooked"
    });
});
//自动约课失败记录 reload
function autoFailBookedReload() {
    autoFailBookedTable.reload("autoFailBooked", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}


//上课态度三星以下
layui.use('table', function () {
    let table = layui.table;
    classAttitudeTable = table;
    table.render({
        elem: '#16',
        url: '/CCNewMain/class/attitude/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {field: 'stuLoginName', title: '学号', fixed: 'left',width: '140',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',28)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'center',width: '100'},
                {field: 'sscName', title: 'SSC',width: '130',fixed: 'left',},
                {title: '三星内容',width :'290',fixed: 'left',
                    templet: function (row) {
                        let html="";
                        if (row.participation>0 && row.participation<4){
                            html="参与度:";
                            for (let i=0;i<row.participation;i++){
                                html+="<img alt=\"星\" src=\"/static/img/raty/star_on.png\">";
                            }

                        }
                        if (row.concentration>0 && row.concentration<4){
                            if (html.length >1){
                                html+="&nbsp;&nbsp;";
                            }
                            html+="专注度:";
                            for (let i=0;i<row.concentration;i++){
                                html+="<img alt=\"星\" src=\"/static/img/raty/star_on.png\">";
                            }

                        }
                        return html;
                    }
                },
                {field: 'releaseTime', title: '课程时间',width: '150',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },

            ]
        ],
        id: "classAttitude"
    });
});

//周课程少于3节
layui.use('table', function () {
    let table = layui.table;
    classWeekInfoTable = table;
    table.render({
        elem: '#17',
        url: '/CCNewMain/class/week/info/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {field: 'stuLoginName', title: '学号', fixed: 'left',width: '140',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',29)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'center',width: '100'},
                {field: 'sscName', title: 'SSC',width: '130',fixed: 'left',},
                {field: 'finishClassNum', title: '上周已上课数',width: '135',fixed: 'center',},
                {field: 'progressClassNum', title: '本周课数(已上/总数)',width: '170',fixed: 'center',},
                {field: 'futureClassNum', title: '下周已约课数',width: '135',fixed: 'center',},

            ]
        ],
        id: "classWeekInfo"
    });
});

function reloadClassWeekInfo() {
    classWeekInfoTable.reload("classWeekInfo", {
        page: {
            curr: 1 //重新从第 1 页开始
        }, where: {
            "weekId": $("#weekId").val()
        }
    });
}

//学员当天课程记录
layui.use('table', function () {
    let table = layui.table;
    classBookedTodayTable = table;
    table.render({
        elem: '#18',
        url: '/CCNewMain/class/today/booked/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {field: 'stuLoginName', title: '学号', fixed: 'left',width: '20%',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',30)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'center',width: '15%'},
                {field: 'sscName', title: 'SSC',width: '20%',fixed: 'left',},
                {field: 'teacherName', title: '老师',width: '15%',fixed: 'center',},
                {field: 'releaseTime', title: '预约课程时间',width :'20%',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },
                {field: 'state', title: '状态',width :'10%',
                    templet: function (row) {
                        let statusName="<span class=\"label label-warning\" style='background-color: #f0ad4e;'>待上课</span>";
                        switch (row.state) {
                            case 1:
                                statusName="<span class=\"label label-warning\" style='background-color: #f0ad4e;'>待上课</span>";
                                break;
                            case 2:
                                statusName="<span class=\"label-success label\">已完成</span>";
                                break;
                            case 3:
                                statusName="<span class=\"label-danger label\">已旷课</span>";
                                break;
                            case 4:
                                statusName="<span class=\"label-default label\">已Void</span>";
                                break;
                            default:
                        }
                        return statusName;
                    }
                }
            ]
        ],
        id: "classBookedToday"
    });
});

function reloadClassBookedToday() {
    classBookedTodayTable.reload("classBookedToday", {
        page: {
            curr: 1 //重新从第 1 页开始
        }, where: {
            "classState": $("#classState").val()
        }
    });
}

//学员最近成绩变化 19
layui.use('table', function () {
    let table = layui.table;
    lastTwoScoreInfoTable = table;
    table.render({
        elem: '#19',
        url: '/CCNewMain/last/two/score/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": ccId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',31)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'center'},
                {field: 'sscName', title: 'SSC',fixed: 'left',},
                {field: 'score1Title', title: '最后成绩',fixed: 'center',},
                {field: 'diffScore', title: '成绩变化',fixed: 'center',
                    templet: function (row) {
                        if (row.diffScore==null){
                            return '';
                        }
                        if (row.diffScore>0){
                            return '<span style="color: red;">' + row.diffScore + '</span>';
                        }else if (row.diffScore<0){
                            return '<span style="color: green;">' +row.diffScore + '</span>';
                        }else {
                            return '<span>' + row.diffScore + '</span>';
                        }

                    }
                },
                {field: 'lastScore', title: '最新成绩',fixed: 'center',},
                {
                    field: '', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="view" onclick="viewScore(' + row.id + ',\''+row.stuLoginName+'\')" href="javascript:void(0);">成绩曲线</a>';
                    }
                }
            ]
        ],
        id: "lastTwoScoreInfo"
    });
});

function reloadLastTwoScoreInfo() {
    lastTwoScoreInfoTable.reload("lastTwoScoreInfo", {
        page: {
            curr: 1 //重新从第 1 页开始
        }, where: {
            // "classState": $("#classState").val()
        }
    });
}